package com.itheima.JDBC02;

import com.itheima.utils.JDBCUtils;
import com.itheima.utils.JDBCUtils2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo4 {
    public static void main(String[] args) throws Exception {

        //2. 获取连接
        Connection conn = JDBCUtils2.getConnection();
        //3. 获取语句执行对象
        Statement st = conn.createStatement();
        //4. 编写SQL
        String sql = "select * from account";
        //5. 执行SQL
        ResultSet rs = st.executeQuery(sql);
        //6. 处理结果集
        while (rs.next()) {
            /*
                获取每一行数据
                    rs.getXxx(字段名);  Xxx类型和数据库列类型匹配
             */
            int id = rs.getInt("id");
            String name = rs.getString("name");
            double money = rs.getDouble("money");
            System.out.println(id + "-" + name + "-" + money);
        }

        JDBCUtils.release(rs, st, conn);
    }
}
